using UnityEngine;

public class HoleKeyboardController : HoleController
{
	private const float JOYSTICK_SENSITIVITY = 12.5f;

	private LayerMask _wallLayer;

	private RaycastHit[] _translationRaycasts;

	private void Start()
	{
		_wallLayer = LayerMask.GetMask("InvisibleWall");
	}

	private void Update()
	{
		Vector3 a = new Vector3(0f, 0f, 0f);
		if (UnityEngine.Input.GetKey(KeyCode.LeftArrow))
		{
			a.x = -1f;
		}
		else if (UnityEngine.Input.GetKey(KeyCode.RightArrow))
		{
			a.x = 1f;
		}
		if (UnityEngine.Input.GetKey(KeyCode.UpArrow))
		{
			a.z = 1f;
		}
		else if (UnityEngine.Input.GetKey(KeyCode.DownArrow))
		{
			a.z = -1f;
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.KeypadPlus))
		{
			_hole.SetLevel(_hole.Level + 1);
			UnityEngine.Debug.Log("Set level " + _hole.Level);
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.KeypadMinus))
		{
			_hole.SetLevel(_hole.Level - 1);
			UnityEngine.Debug.Log("Set level " + _hole.Level);
		}
		if (Mathf.Abs(a.x) > 0f || Mathf.Abs(a.z) > 0f)
		{
			Quaternion rotation = Quaternion.Euler(new Vector3(0f, MathUtils.Vector2ToAngle(new Vector2(0f - a.x, a.z)), 0f));
			_hole.SetRotation(rotation);
		}
		if (!base.CanMove)
		{
			return;
		}
		Vector3 vector = a * Time.deltaTime * 12.5f;
		float num = _hole.Size * 0.4f;
		if (_hole.IsDead)
		{
			num = (_hole.Size - 2f) * 0.4f;
		}
		_translationRaycasts = Physics.SphereCastAll(_hole.CurrentPosition, num, _hole.ForwardDirection, vector.magnitude * _hole.Speed, _wallLayer);
		if (_translationRaycasts.Length > 0)
		{
			RaycastHit[] translationRaycasts = _translationRaycasts;
			for (int i = 0; i < translationRaycasts.Length; i++)
			{
				RaycastHit raycastHit = translationRaycasts[i];
				vector = Vector3.ProjectOnPlane(vector, raycastHit.normal);
			}
		}
		_hole.TranslatePosition(vector * _hole.Speed);
		if (a.sqrMagnitude > 0f && vector.sqrMagnitude < 1E-11f && !Physics.Raycast(_hole.CurrentPosition, _hole.ForwardDirection, num, _wallLayer))
		{
			_hole.TranslatePosition(a * Time.deltaTime * 12.5f);
		}
	}
}
